package myTest;
import java.io.*;

public class statisticsBusAndStation{
	static String[] bus = new String[400];
	static String[] station = new String[3000];
	static int busCount=0;
	static int stationCount=0;
	
	public static boolean isIn(String str){
		int i=0;
		while(station[i]!=null)
			if(station[i++].compareTo(str)==0)
				return true;
		return false;
	}
	
	public static void main(String[] args){
		String busFile="C:\\Users\\ChengXin\\Desktop\\bus.txt";
		
		try{
			String s;
			BufferedReader in = new BufferedReader(new FileReader(busFile));
			while((s = in.readLine()) != null){
				String array[] = s.split(" ");
				bus[busCount++]=array[0];
				for (int i=1; i<array.length; i++)
					if(!isIn(array[i]))
						station[stationCount++]=array[i];
			}
			String FilePath="C:\\Users\\ChengXin\\Desktop\\busANDstation.txt";
			FileOutputStream out=new FileOutputStream(FilePath);
			BufferedWriter buffWriter = new BufferedWriter(new OutputStreamWriter(out));

            buffWriter.write(busCount+" "+stationCount+"\r\n");
            for(int i=0; i<busCount; i++)
            	buffWriter.write(bus[i]+" ");
            buffWriter.write("\r\n");
            for(int i=0; i<stationCount; i++)
            	buffWriter.write(station[i]+" ");
            
            buffWriter.flush();
		}
		catch(Exception e){
			System.out.print(e.toString());
		}
	}
}